import {accAdd,accMul ,accSub , addZero} from "@/static/js/GeneralUtil.js";
import {DateTime , getCurrentTimestamp} from "@/static/js/DateUtil.js";
/**
 * 生成销售明细JSON
 * @param {Object} item
 * @param {Object} Sales_Order_SerialNumber
 * @param {Object} index
 * @param {Object} Member_Points_SerialNumber
 * @param {Object} Deduction_Ratio
 * @param {Object} Enterprise_Info_SerialNumber
 */
function salesOrderDdetailJSON(item , Sales_Order_SerialNumber , index , Member_Points_SerialNumber,Deduction_Ratio,Enterprise_Info_SerialNumber){
	return {
		Sales_Order_Detail_SerialNumber:Sales_Order_SerialNumber + '_' + addZero(index,3),
		Sales_Order_SerialNumber,
		Sales_Unit_Price_Stock_SerialNumber:item.Execute_Stock_SerialNumber,//仓库
		Supplier_Article_SerialNumber:item.Supplier_Article_SerialNumber,//供应商品编号
		Quantity:item.Quantity,//数量
		Refundable_Quantity:item.Quantity,//数量
		Refunded_Quantity:0,
		Unit_Price:item.Unit_Price,//吊牌价
		Sales_Unit_Price:item.Sales_Unit_Price,//单价
		Sales_Point:item.Sales_Point,//消耗总积分
		Refundable_Point:item.Sales_Point,//可退款积分
		Refunded_Point:0,//
		Reality_Amount:item.Reality_Amount,//实际金额
		Refundable_Amount:item.Reality_Amount,//可退款金额
		Refunded_Amount:0,//已退款金额
		Amount:item.Amount,//总金额
		Deduction_Ratio,//积分抵扣比例
		Deduction_Type:item.Deduction_Type,
		Deduction_Limit:item.Deduction_Limit,
		Article_Name:item.Article_Name,
		Specifications_Name:item.Specifications_Name,
		Picture_URL:item.Picture_URL,
		Brand_SerialNumber:item.Brand_SerialNumber,
		Category_SerialNumber:item.Category_SerialNumber,
		Series_SerialNumber:item.Series_SerialNumber,
		Item_SerialNumber:item.Item_SerialNumber,
		Specifications_Picture_URL:item.Specifications_Picture_URL,
		Store_SerialNumber:item.Store_SerialNumber,
		Weight:item.Weight,
		Weight_Unit:item.Weight_Unit,
		Refund_Type:'',
		Order_Type:'0',
		Supplier_SerialNumber:item.Supplier_SerialNumber,
		Activity_SerialNumber:item.Activity_SerialNumber,
		Member_Points_SerialNumber,
		Enterprise_Info_SerialNumber,
		Reconciliation_Status:'00'
	}
}
/**
 * 生成收款明细JSON
 * @param {Object} item
 * @param {Object} Collection_Type
 * @param {Object} Amount
 */
function collectionDetailJSON(item,Collection_Type,Amount,Collection_Related_Number){
	return {
		Collection_Detail_SerialNumber:'',
		Collection_SerialNumber:'',
		Store_SerialNumber:item.Store_SerialNumber,
		Sales_Order_SerialNumber:item.Sales_Order_SerialNumber,
		Sales_Order_Detail_SerialNumber:item.Sales_Order_Detail_SerialNumber,
		Collection_Order_Number:'',
		Collection_Type,
		Collection_Related_Number,
		Amount,
		Other_Type:'',
		Gift_Type:'',
		Gift_Amount:'',
	}
}
/**
 * 生成提交购物车JSON
 * @param {Object} business_shopping_trolley
 * @param {Object} Quantity
 * @param {Object} Open_ID
 * @param {Object} Supplier_Article_SerialNumber
 * @param {Object} Activity_SerialNumber
 */
function shoppingTrolleyJSON(business_shopping_trolley, Quantity,Open_ID,Supplier_Article_SerialNumber,Activity_SerialNumber){
	let obj;
	if (business_shopping_trolley.length > 0) {
		business_shopping_trolley[0].Quantity = parseInt(business_shopping_trolley[0].Quantity) + Quantity;
	    obj = { 
			Modify: { 
				business_shopping_trolley
			} 
		}
	} else {
	    obj = { 
			Add: {
				business_shopping_trolley: [{
					Shopping_Trolley_Sales_Order_SerialNumber: '',
					Open_ID,
					Supplier_Article_SerialNumber,
					Quantity,
					Activity_SerialNumber,
				}]
			}
		}                        
	}
	return obj;
}
module.exports = {
	salesOrderDdetailJSON,
	collectionDetailJSON,
	shoppingTrolleyJSON
}